<%@page language="java" isELIgnored="false" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<jsp:directive.include file="/WEB-INF/sitemesh-decorators/include.jsp"/>

<fmt:setBundle basename="bundles.thesis-resources"/>
<html>
<head>

<link rel="stylesheet" href="<%=request.getContextPath()%>/includes/css/jquery-ui-1.8.21.custom.css" type="text/css"/>
<link rel="stylesheet" href="<%=request.getContextPath()%>/includes/css/AutoComplete.css" type="text/css" media="all" />
<script src="<%=request.getContextPath()%>/includes/js/jquery-ui-1.8.21.custom.min.js"></script>
<title>Edit <fmt:message key="thesis.title"/></title>

<script type="text/javascript">
$(function() {
	var studentList = '${studentList}';
	var studentStr = studentList.substring(studentList.indexOf('{')+1,studentList.indexOf('}'));
	studentStr = studentStr.replace(/=/g,":");
	var studentArr=studentStr.split(',');
	var tempArray = new Array();
	var tempStr="";
	for(var i=0;i<studentArr.length;i++){
		tempStr = studentArr[i];
		tempStr = tempStr.substring(tempStr.indexOf(":")+1);
		tempArray[i]= tempStr;
	}
	$( "#studentName").autocomplete({
		source: tempArray,
		select: function(e, ui) {
			//create formatted data
			var student = ui.item.value;
			getId(student,studentArr);
			$("#studentName").val(student);
		},
		close: function(event, ui) {
		}
	});
	
});
function getId(str,arr){
	var key = "";
	var value ="";
	var tempStr="";
	for(var i=0;i<arr.length;i++){
		tempStr = arr[i];
		tempStr = tempStr.replace(/^\s+|\s+$/g,'');
		key=tempStr.substring(0,tempStr.indexOf(":"));
		value = tempStr.substring(tempStr.indexOf(":")+1);
		if(value==str){
			$("#thesis_student").val(key);
		}
	}
}
$(document).ready(function() {
	//alert('${facultyName}');
	$("#studentName").val('${studentName}');
	$("#thesis_student").val('${studentId}');
	if('${studentId}'==''){
		$('#studentTitle').show();
		$('#studentName').show();
		
	}else{
		$('#studentTitle').hide();
		$('#studentName').hide();
	}
		
	//alert($("#facultyName").val());	  
	});
</script>

<body>
</head>

<div id="contentarea">   
<script type="text/javascript">
$().ready(function() {
	$('#thesisform').validate();
});
</script>    
	<div id="lb"><div id="rb"><div id="bb"><div id="blc">
	<div id="brc"><div id="tb"><div id="tlc"><div id="trc">
	<div id="content">
		<h1><%-- <fmt:message key="navigation.edit"/> --%> <fmt:message key="thesis.title"/></h1>
		<div class="navitem"><a class="button" href="${pageContext.request.contextPath}/indexThesis"><span><img src="includes/images/icons/back.gif" /><fmt:message key="navigation.back"/></span></a></div>
		<form:form id="thesisform" action="${pageContext.request.contextPath}/saveThesis" method="POST" modelAttribute="thesis">
			<form:hidden id="thesis_thesisId" path="thesisId"/>
			<table cellpadding="0" cellspacing="0" id="viewTable">
				<tbody>
									
					<tr>
						<td class="label" valign="top">
							<fmt:message key="thesis.title.title"/>:
						</td>
						<td>
							<form:input id="thesis_title" path="title" cssStyle="width:300px;" class="required"/>
							<!-- <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : "thesis_title",widgetType : "dijit.form.ValidationTextBox",widgetAttrs : {promptMessage: "<fmt:message key="thesis.title.help"/>"}})); </script> -->
						</td>
					</tr>
					<tr>
						<td class="label" valign="top">
							<fmt:message key="thesis.abstract_.title"/>:
						</td>
						<td>
							<form:textarea id="thesis_abstract_" path="abstract_" rows="8" cssStyle="width:300px;" class="required"/>
							<!-- <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : "thesis_abstract_",widgetType : "dijit.form.ValidationTextBox",widgetAttrs : {promptMessage: "<fmt:message key="thesis.abstract_.help"/>"}})); </script> -->
						</td>
					</tr>
					<tr>
						<td class="label" valign="top">
							<fmt:message key="thesis.proposalattempts.title"/>:
						</td>
						<td>
							<form:input id="thesis_proposalAttempts" path="proposalAttempts" cssStyle="width:300px;"/>
							<!-- <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : "thesis_proposalAttempts",widgetType : "dijit.form.NumberTextBox",widgetAttrs : {promptMessage: "<fmt:message key="thesis.proposalattempts.help"/>", constraints : {places:0}}})); </script> -->
						</td>
					</tr>
					<tr>
						<td class="label" valign="top">
							<fmt:message key="thesis.defenseattempts.title"/>:
						</td>
						<td>
							<form:input id="thesis_defenseAttempts" path="defenseAttempts" cssStyle="width:300px;"/>
							<!-- <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : "thesis_defenseAttempts",widgetType : "dijit.form.NumberTextBox",widgetAttrs : {promptMessage: "<fmt:message key="thesis.defenseattempts.help"/>", constraints : {places:0}}})); </script> -->
						</td>
					</tr>
					<tr>
						<td class="label" valign="top">
							<fmt:message key="thesis.startdate.title"/>:
						</td>
						<td>
							<input id="thesis_startDate" name="startDate" type="text" value="<fmt:formatDate value="${thesis.startDate.time}" pattern="MM/dd/yyyy h:mm a"/>" style="width:300px;"/>
							<!-- <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : "thesis_startDate",widgetType : "dijit.form.ValidationTextBox",widgetAttrs : {promptMessage: "<fmt:message key="navigation.dateTime.title"/>"}})); </script> -->
						</td>
					</tr>
					<tr>
						<td class="label" valign="top">
							<fmt:message key="thesis.doi.title"/>:
						</td>
						<td>
							<form:input id="thesis_doi" path="doi" cssStyle="width:300px;"/>
							<!-- <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : "thesis_doi",widgetType : "dijit.form.ValidationTextBox",widgetAttrs : {promptMessage: "<fmt:message key="thesis.doi.help"/>"}})); </script> -->
						</td>
					</tr> 
					<tr>
						<td id="studentTitle" class="label" valign="top">
							<fmt:message key="student.title"/>:
						</td> 
						<td>
							<input type="text" id="studentName" class="required" />
							 <!-- This is just for display purpose -->
							
							<form:hidden id="thesis_student" path="student"/>  
							<%-- <input type="hidden" name="studentId" id ="thesis_student"/>--%>
							<%-- <form:select id="thesis_title" path="student" cssStyle="width:300px;">
								<form:options items="${studentList }" itemLabel="firstName" itemValue="studentId"/>
							</form:select>--%>
							<!-- <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : "thesis_title",widgetType : "dijit.form.ValidationTextBox",widgetAttrs : {promptMessage: "<fmt:message key="thesis.title.help"/>"}})); </script> -->
						</td>
					</tr>
				</tbody>
			</table>
			<span class="inputbutton"><input class="savebutton" id="save" type="submit" value="<fmt:message key="navigation.save"/>"/></span>
			<script type="text/javascript">Spring.addDecoration(new Spring.ValidateAllDecoration({elementId:'save', event:'onclick'}));</script>
		</form:form>
		<div class="clear">&nbsp;</div>
	</div>
	</div></div></div></div>
	</div></div></div></div>
</div>
</body>
</html>